<?php
#基础函数
include_once('_path.php');
include_once("../includes/init.php");

#翻页
$page = trim($_GET['page']) + 0; if ($page == "") { $page = $_COOKIE['bmpage']; }
#搜索
$do = trim($_GET['do']); if ($do == "") { $do = $_COOKIE['bmdo']; }
#！！搜索
if ($do == 'search') {
	$word = trim($_GET['word']); if (!isset($_GET['word'])) { $word = $_COOKIE['bmword']; }	
} 

#获得总页数
$sql = "SELECT count(*) total FROM thumb_file WHERE 1=1".
iif(strlen($word) > 0, " AND user_id ='$word'");
$rs = $database->queryFirst($sql);
$total_series = $rs["total"];
$total_page = ceil($total_series / 50);
#计算页数
if ($total_page < 1) $total_page = 1;
if ($page < 1) $page = 1;
if ($page > $total_page) $page = $total_page;

set_cookie('bmpage', $page, time() + 604800);
set_cookie('bmword', $word, time() + 604800);
set_cookie('bmdo', $do, time() + 604800);

#正式读内容
$sql = "SELECT mg.* FROM thumb_file mg WHERE 1=1".
iif(strlen($word) > 0, " AND user_id ='$word'").
" ORDER BY id DESC LIMIT ".(($page - 1) * 50).", 50";
$rs = $database->queryArray($sql);

add_log('show', 'thumb');
$css = array('index', 'table');
$js = array();

include_once("../layout/_header.php");
?>
<div id="path">
	<ul>
		<li><a href="<?php echo _CONST_WEB_URL ?>"><?php echo _CONST_WEB_NAME?></a></li>
		<li><a href="<?php echo _CONST_BACKEND_URL ?>index.php">Backend</a></li>
		<li>Thumb</li>
	</ul>
	<a href="<?php echo _CONST_BACKEND_URL ?>logout.php" class="r" style="margin:2px 10px"><span class="thumbout">logout</span></a>
</div>

<div id="content">
	<ul id="submenu">
		<li class="current"><a href="index.php" class="button"><span class="list">List</span></a></li>
	</ul>
	<span style="margin:7px 10px 2px 50px;" class="l">Current User:<?php echo $_SESSION['bname']?>&nbsp;&nbsp;<?php echo gmdate('D M j, Y h:ia T', _CONST_TIMENOW) ?></span>
	<div style="float:right;margin-right:10px;">
	<form>
	UserID
	<input type="text" name="word" value="<?= htmlspecialchars($word) ?>" size="20" />
	<input type="submit" name="do" value="search" class="button">
	</form>
	</div>
	<?php
	if (sizeof($rs) > 0){
		?>
		<div class="cr"></div>
	    <form action="thumb_edit.php" name="form" id="form" method="post">
	    <input type="hidden" name="type" value="" />
		<table class="list" cellspacing="0">
			<tr>
				<th class="no">&nbsp;</th>
				<th class="no">ID</th>
				<th width="100%" class="no">UserID</th>
				<th class="no">200X FileName</th>
				<th class="no">450X FileName</th>
				<th class="no">Org FileName</th>
				<th class="no">Createtime</th>
				<th class="no">&nbsp;</th>
			</tr>
			<?php
			for($i=0;$i<sizeof($rs);$i++){
				$r = $rs[$i];
				?>
				<tr>
					<td class="no"><input type="checkbox" name="request_ids[]" value="<?php echo $r['id'] ?>"></td>
					<td class="no"><?php echo $r['id']?></td>
					<td class="no"><a href="<?php echo _CONST_BACKEND_URL."user/user_edit.php?func=edit&user_id=".$r['user_id']?>"><?php echo $r['user_id'] ?></a></td>
                  <td class="no"><a href="<?php echo _CONST_PIC_URL.'thumb/'.$r['user_id']."/1_".$r['filename']?>" target="_blank">View 200X SIZE</a></td>
					<td class="no"><a href="<?php echo _CONST_PIC_URL.'thumb/'.$r['user_id']."/2_".$r['filename']?>" target="_blank">View 500X SIZE</a></td>
					<td class="no"><a href="<?php echo _CONST_PIC_URL.'thumb/'.$r['user_id']."/".$r['filename']?>" target="_blank">View Org SIZE</a></td>
					<td class="no"><?php echo gmdate('m/d Y H:i:s', $r['createtime']) ?></td>
					<td colspan="2" class="action no">
					<a href="thumb_edit.php?request_id=<?php echo $r['id'] ?>" onclick="return warning();" class="button"><img src="<?php echo _CONST_BACKEND_URL ?>media/delete.png" /> Delete</a>
					</td>
				</tr>
				<?php
			}
			?>
			<tr><td colspan="8" class="action" style="padding:5px;">
				<a href="javascript:checkAll('request_ids[]')" class="button"><span class="on">checkAll</span></a> &nbsp;
				<a href="javascript:clearAll('request_ids[]')" class="button"><span class="off">clearAll</span></a> &nbsp; &nbsp; &nbsp; &nbsp;
				<a href="javascript:document.form.type.value='delete';document.form.submit();" onclick="return checkId('request_ids[]');" class="button"><span class="delete">Delete</span></a>
			</td></tr>
		</table>
		</form>
	<?php
	}else{
		?><div class="border cr">No Record</div><?php
	} // if ($st->num_rows() > 0)

	?>			
	<?php if ($total_page > 1) { ?>
	<ul id="nav">
		<li <?php echo iif($page == 1, 'class="disabled"><a>', '><a href="?page=1">') ?><img src="<?php echo _CONST_BACKEND_URL ?>media/first.png" style="float:left;"></a></li>
		<li <?php echo iif($page < 2, 'class="disabled"><a>', '><a href="?page='.($page - 1).'">') ?><img src="<?php echo _CONST_BACKEND_URL ?>media/prev.png" style="float:left;"></a></li>
		<li class="jump"><form><input type="text" name="page" value="<?php echo $page ?>" size="3" style="float:left;margin-top:1px;width:20px;border:1px #ccc solid;font-size:10px;padding:0 2px;"> <span style="float:left;padding-left:2px;padding-top:2px;width:30px;"> of <?php echo $total_page ?></span><input type="image" src="<?php echo _CONST_BACKEND_URL ?>media/go.png" style="margin-left:4px;float:left;"></form></li>
		<li <?php echo iif($page > $total_page - 1, 'class="disabled"><a>', '><a href="?page='.($page + 1).'">') ?><img src="<?php echo _CONST_BACKEND_URL ?>media/next.png" style="float:left;"></a></li>
		<li <?php echo iif($page == $total_page, 'class="disabled"><a>', '><a href="?page='.$total_page.'">') ?><img src="<?php echo _CONST_BACKEND_URL ?>media/last.png" style="float:left;"></a></li>
	</ul>
	<?php } ?>
	
</div>
<?php
include_once("../layout/_footer.php");
?>